home *** CD-ROM | disk | FTP | other *** search
/ Champak 114 / Vol 114.iso / games / spongebo.swf / scripts / DefineSprite_225_char / frame_1 / DoAction_2.as next >
Encoding:
Text File  |  2010-08-12  |  3.3 KB  |  143 lines

  1. function eventUp()
  2. {
  3.    posX = Math.floor(this._x / tileW);
  4.    posY = Math.floor(this._y / tileH);
  5.    posFloorY = posY + 1;
  6.    posNextY = posY - 1;
  7.    curTileVal = map[posY][posX];
  8.    floorTileVal = map[posFloorY][posX];
  9.    nextTileVal = map[posNextY][posX];
  10.    nextFloorTileVal = map[posNextY + 1][posX];
  11.    newY = this._y - spd;
  12.    if(curTileVal >= 5 && nextTileVal >= 5)
  13.    {
  14.       this.art.gotoAndStop("up");
  15.       this.myDir = "up";
  16.       txCenter = posX * tileW + tileW / 2;
  17.       this._x = txCenter;
  18.       if(nextTileVal >= 5)
  19.       {
  20.          this._y = newY;
  21.       }
  22.       else
  23.       {
  24.          tyCenter = posY * tileW + tileW / 2;
  25.          if(newY < tyCenter)
  26.          {
  27.             newY = tyCenter;
  28.          }
  29.          this._y = newY;
  30.       }
  31.    }
  32. }
  33. function eventDown()
  34. {
  35.    posX = Math.floor(this._x / tileW);
  36.    posY = Math.floor(this._y / tileH);
  37.    posFloorY = posY + 1;
  38.    posNextY = posY + 1;
  39.    curTileVal = map[posY][posX];
  40.    floorTileVal = map[posFloorY][posX];
  41.    nextTileVal = map[posNextY][posX];
  42.    nextFloorTileVal = map[posNextY + 1][posX];
  43.    newY = this._y + spd;
  44.    if(curTileVal >= 5)
  45.    {
  46.       txCenter = posX * tileW + tileW / 2;
  47.       this._x = txCenter;
  48.       if(nextTileVal >= 5)
  49.       {
  50.          this.art.gotoAndStop("down");
  51.          this.myDir = "down";
  52.          this._y = newY;
  53.       }
  54.       else
  55.       {
  56.          tyCenter = posY * tileW + tileW / 2;
  57.          if(newY >= tyCenter)
  58.          {
  59.             newY = tyCenter;
  60.             this._y = newY;
  61.          }
  62.          else
  63.          {
  64.             this.art.gotoAndStop("down");
  65.             this._y = newY;
  66.          }
  67.       }
  68.    }
  69. }
  70. function eventLeft()
  71. {
  72.    posX = Math.floor(this._x / tileW);
  73.    posY = Math.floor(this._y / tileH);
  74.    posFloorY = posY + 1;
  75.    posNextX = posX - 1;
  76.    curTileVal = map[posY][posX];
  77.    floorTileVal = map[posFloorY][posX];
  78.    nextTileVal = map[posY][posNextX];
  79.    nextFloorTileVal = map[posFloorY][posNextX];
  80.    newX = this._x - spd;
  81.    if(nextTileVal > 0)
  82.    {
  83.       this._x = newX;
  84.       this.art.gotoAndStop("left");
  85.       this.myDir = "left";
  86.       tyCenter = posY * tileW + tileW / 2;
  87.       this._y = tyCenter;
  88.    }
  89.    else
  90.    {
  91.       txCenter = posX * tileW + tileW / 2;
  92.       if(newX < txCenter)
  93.       {
  94.          newX = txCenter;
  95.       }
  96.       this._x = newX;
  97.    }
  98. }
  99. function eventRight()
  100. {
  101.    posX = Math.floor(this._x / tileW);
  102.    posY = Math.floor(this._y / tileH);
  103.    posFloorY = posY + 1;
  104.    posNextX = posX + 1;
  105.    curTileVal = map[posY][posX];
  106.    floorTileVal = map[posFloorY][posX];
  107.    nextTileVal = map[posY][posNextX];
  108.    nextFloorTileVal = map[posFloorY][posNextX];
  109.    newX = this._x + spd;
  110.    if(nextTileVal > 0)
  111.    {
  112.       this._x = newX;
  113.       tyCenter = posY * tileW + tileW / 2;
  114.       this._y = tyCenter;
  115.       this.art.gotoAndStop("right");
  116.       this.myDir = "right";
  117.    }
  118.    else
  119.    {
  120.       txCenter = posX * tileW + tileW / 2;
  121.       if(newX > txCenter)
  122.       {
  123.          newX = txCenter;
  124.       }
  125.       this._x = newX;
  126.    }
  127. }
  128. function eventFire()
  129. {
  130.    if(scripts.gameOn)
  131.    {
  132.       posX = Math.floor(this._x / tileW);
  133.       posY = Math.floor(this._y / tileH);
  134.       scripts.fireMustard();
  135.    }
  136. }
  137. map = scripts.map;
  138. tileW = 30;
  139. tileH = 30;
  140. cTile = tileW / 2;
  141. var hTile = tileW / 2;
  142. var spd = 5;
  143.